import Vue from 'vue'

Vue.filter('unitConversion', function (size) {
	if (size == null) {
		size = 0;
	}

	if (size >= 1024 && size < (1024 * 1024)) {
		size = (size / 1024).toFixed(2) + "KB";
	} else if (size >= (1024 * 1024) && size < (1024 * 1024 * 1024)) {
		size = (size / (1024 * 1024)).toFixed(2) + "MB";
	} else if (size >= (1024 * 1024 * 1024) && size < (1024 * 1024 * 1024 * 1024)) {
		size = (size / (1024 * 1024 * 1024)).toFixed(2) + "GB";
	} else if (size >= (1024 * 1024 * 1024 * 1024) && size < (1024 * 1024 * 1024 * 1024 * 1024)) {
		size = (size / (1024 * 1024 * 1024 * 1024)).toFixed(2) + "TB";
	} else {
		size += "B";
	}

	return size;
})

Vue.filter('formatPercent', function (num) {
	return num.toFixed(2);
})